<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
      <%@ page import = "java.sql.*" %>
  <%@ page import = "com.weibo.dao.connDB"%>
  
<%   
 	connDB db = new connDB();
	db.getConnection();
%>
<%String name = (String)session.getAttribute("nickname");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
//<meta http-equiv="refresh" content="2;URL=searchU.jsp"> 
<title>Following...</title>
</head>
<%

	String NewName = request.getParameter("FocusName");
	
	String checkName = "select * from follow where id1= '"+name+"' and id2 = '"+NewName+"'";  
	
	/*give the follow id*/
	int id=0;
	int countChoose = 0;
	String getfollow = "select * from follow";
	db.rs = db.executeQuery(getfollow);
	
	if(db.rs.next()){countChoose++;}
		
		if(countChoose == 0){
		String initialize = "insert into follow values(0,null,null)"; 
		db.executeUpdate(initialize);}
		
		db.rs.last();
		id = db.rs.getInt("follow_id");
		//System.out.println(id);
		//System.out.println(id+"final");
		id+=1;
	
	db.rs = db.executeQuery(checkName);
	int count = 0;
	if(db.rs.next()){count+=1;}
	
	if(count < 1){
	String sql="insert into follow values('"+id+"','"+name+"','"+NewName+"')";
	
	db.executeUpdate(sql);
	//System.out.println(id+"1111111111111111111"+name +"1111111111111" +NewName+"111111111111111"+c);

	
	String countFans = session.getAttribute("Fans").toString();
	String countFocus = session.getAttribute("Focus").toString();
	
	int a = Integer.parseInt(countFocus)+1;
	int b = Integer.parseInt(countFans)+1;
	
	
	String sql_updatea = "update user set focus = '"+Integer.toString(a)+"' where nickname = '"+name+"'";
	String sql_updateb = "update user set fans = '"+Integer.toString(b)+"' where nickname = '"+NewName+"'";
	
	db.executeUpdate(sql_updatea);
	db.executeUpdate(sql_updateb);
	
	System.out.print("Focus"+a+"follow_act.jsp");
	
	session.setAttribute("Focus",a);
	response.setHeader("0","home.jsp");
	}else{
		response.sendRedirect("home.jsp");}
	db.close();
	
%>
<body >
<br>
<br>
<DIV align="center">
<p ><font face="Arial" size="5">Yor are following <%=NewName%></font></p>

<br/>
  <img  src="images/loadingAnimationv3.gif">
</DIV>
</body>
</html>